/*
 * TestDumpCPPListToken.c
 *
 *  Created on: 2012/05/31
 *      Author: guanxiaoying
 */
#include "TestDump.h"

static VOID dumpPPToken( AST astToken ){
	AST codescp = CPPTokenList.getCodeScp(astToken);
	PSZ pszName = CPPTokenList.getTokenLabel(astToken);

	sprintf( tempBuf, header_format, dumpGetStr(XML_RECORD), astToken );
	dumpOutputStream( tempBuf );

	dumpCodeScopeAsField( codescp );

	sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_NAME), "" );
	dumpOutputStream( tempBuf );
	if( pszName != NULL ){
		dumpParameterStr( pszName );
	}
	sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_NAME)  );
	dumpOutputStream( tempBuf );

	sprintf( tempBuf, tail_format, dumpGetStr(XML_RECORD) );
	dumpOutputStream( tempBuf );
}
VOID DumpPPTokenList( PSZ szPath, PSZ postfix ){
	AST astPPToken;
	AST astMax = CPPOutput.CPPTokenList->getMax();
	if( szPath == NULL ){
		return;
	}
	strcpy( file_buf, szPath );
	file_buf[strlen(szPath)] = '\0';
	strcat(file_buf, postfix );
	file_buf[strlen(szPath)+strlen(postfix)] = '\0';
	if( COEXIT_SUCCESS == dumpOutputStreamInit_file(file_buf)){
		sprintf( tempBuf, top_header, dumpGetStr(XML_PPTOKENLIST) );
		dumpOutputStream( tempBuf );
		for( astPPToken = MIN_ARRAY; astPPToken <= astMax; astPPToken++ ){
			dumpPPToken( astPPToken );
		}
		sprintf( tempBuf, top_end, dumpGetStr(XML_PPTOKENLIST) );
		dumpOutputStream( tempBuf );
		dumpOutputStreamEnd_file();
	}
}

